package conservare.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DataUtil {

	public  static synchronized Calendar  zerarHoraData(final Date dataEntrada){
		
		Calendar cal = Calendar.getInstance();
		cal.setTime(dataEntrada);
		cal.set(Calendar.HOUR_OF_DAY, 0);  
		cal.set(Calendar.MINUTE, 0);  
		cal.set(Calendar.SECOND, 0);  
		cal.set(Calendar.MILLISECOND, 0); 
		
		return cal;
	}
	
	 public static synchronized String getFormattedTime(Date time, String format) throws ParseException {  
	        if (time == null) {  
	            return null;  
	        }  
	  
	        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);  
	        return simpleDateFormat.format(time);
	        
	 }  
	 
	 public static synchronized String getFormattedDate(Date dataEntrada, String format) throws ParseException {
		 
		 if (dataEntrada == null) {  
	            return null;  
	     }  
		 
		 
		 SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);  
		  
		 return simpleDateFormat.format(dataEntrada);
		 
	 }
	 
	 public static synchronized String getFormattedDate(String dateInString, String format) throws ParseException {
		 
		 if (dateInString == null) {  
	            return null;  
	     }  
		 
		 
		 SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);  
		 Date dataEntrada = simpleDateFormat.parse(dateInString);
		  
		 return simpleDateFormat.format(dataEntrada);
		 
	 }
	 
	 public static synchronized Date StringToDate(String dateInString) throws ParseException {
		 if (dateInString == null) {  
	            return null;  
	     }  
		 
		 return new SimpleDateFormat().parse(dateInString);  
		 
	 }
}
